#include <iostream>
#include "../comm/httplib.h"
#include "oj_control.hpp"

using namespace httplib;
using namespace ns_control;

static Control *ctrl=nullptr;

int main()
{
    httplib::Server srv;
    
    //获得所有的题目路由
    srv.Get("/all_questions",[](const Request& req,Response& resp){
        std::string html;
        ctrl->AllQuestions(&html);
        resp.set_content("这里是所有的题目内容","text/plain; charset=utf-8");
        
    });
    //获取题目的内容,能捕获/question/123,这样的路径
    srv.Get(R"(/question/(\d+))",[](const Request& req,Response& resp){
        std::string num=req.matches[1];//说明是按照'\'分割的
        std::string html;
        
        ctrl->Question(num,&html);
        resp.set_content("这里指定的一道题目："+num,"text/plain;charset=utf-8");
    });

    //用户提交的代码，我们提供判断功能（1.测试用例，2.compile_and_run）
    srv.Get(R"(/question/(\d+))", [](const Request &req, Response &resp){
        std::string num=req.matches[1];//说明是按照'\'分割的
        resp.set_content("这里指定的一道题目："+num,"text/plain;charset=utf-8"); 
    });
    
    srv.set_base_dir("./wwwroot");
    srv.listen("0.0.0.0",8080);
    return 0;
}



